package
{
	import flash.display.MovieClip;
	import flash.display.Stage;


	public class StatePopup extends State
	{
		protected var movieclip:MovieClip;
		protected var objects:Array = new Array();
		protected var text:String;
		protected var b1Text:String;
		protected var b2Text:String;
		public function StatePopup(s:String,b1:String,b2:String=null)
		{
			super();
			//movieclip = CommonResource.duplicateDisplayObject(CommonResource.mvDialog) as MovieClip;
			//movieclip = CommonResource.mvDialog;
			//movieclip.SetContainer(FBGame.mainFBGame);
			this.text = s;
			this.b1Text = b1;
			this.b2Text = b2;
			
		}
		public override function Render(g:MyGraphics):void
		{
			if(this.stateIndex - 1 >= 0)
				FBGame.stateStack.GetStateAt(this.stateIndex - 1).Render(g);
			
		}
		public override function Update(dt:int):void
		{
			if(this.stateIndex - 1 >=0)
				FBGame.stateStack.GetStateAt(this.stateIndex - 1).Update(dt);
		}
		public override function Init():void
		{
			var s:Vector.<ExternalResource> = new Vector.<ExternalResource>();
			s.push(new ExternalResource("",ExternalResource.movieClip,CommonResource.clone(CommonResource.mvDialog)));
			FBGame.stateStack.Push(new StateLoading(s,objects,this,true));
			
			
			
		}
		public override function LoadComplete(success:Boolean):void
		{
			if(success)
			{
				movieclip = objects[0];
				movieclip.SetContainer(FBGame.mainFBGame);
				movieclip.SetDialogText(text);
				if(b2Text == null)
				{
					movieclip.SetDialogOneButton(b1Text);
				}
				else
				{
					movieclip.SetDialogTwoButton(b1Text,b2Text);
				}
				FBGame.mainFBGame.stage.addChild(movieclip);
			}
			else
			{
				
			}
		}
		public override function Release():void
		{
			FBGame.mainFBGame.stage.removeChild(movieclip);
		}
		public override function ReceiveMessage(mess:String,param:Array,sender:MovieClip):void
		{
			switch(mess)
			{
				case "button":
					FBGame.stateStack.Pop();
					break;
			}
		}
	}
}